import { IParam, IContext, DataServiceBase, IHttpResponse } from '@/core';
import { Auth_userDTOHelp } from '../dto-help/auth-user-helps';
import { Auth_user } from '../auth-user';
import Auth_userKeys from '../auth-user-keys';

/**
 * 认证用户服务对象基类
 * 基于template/src/api/{{appEntities}}/data-service/{{appEntities}}-service-base.ts.hbs生成
 *
 * @export
 * @class Auth_user
 * @extends {EntityBaseService}
 */
export class Auth_userServiceBase extends DataServiceBase<Auth_user> {
	/**
	 * 存储模式
	 *
	 * @type {(0 | 1 | 3 | 4)} 无本地存储 | 仅本地存储 | 本地及远程存储 | DTO无存储
	 * @memberof Auth_userServiceBase
	 */
	readonly storageMode: number = 0;

	/**
	 * Creates an instance of Auth_userServiceBase.
	 *
	 * @param {*} [opts={}]
	 * @memberof Auth_userServiceBase
	 */
	constructor(opts: IParam = {}) {
		super(opts, 'Auth_user');
	}

	/**
	 * 初始化基础数据
	 *
	 * @protected
	 * @memberof Auth_userServiceBase
	 */
	protected initBasicData() {
		this.systemName = 'uaa';
		this.appName = 'web';
		this.appEntityName = 'auth_user';
		this.appEntityCodeName = 'auth_user';
		this.appEntityCodeNames = 'auth_users';
		this.appEntityKeyCodeName = 'id';
		this.appEntityTextCodeName = 'display_name';
	}

	/**
	 * 构造实体
	 *
	 * @protected
	 * @param {IParam} data
	 * @param {IContext} [context]
	 * @return {*} { Auth_user }
	 * @memberof Auth_userServiceBase
	 */
	protected newEntity(data: IParam, context: IContext = {}): Auth_user {
		return new Auth_user(data);
	}

	/**
	 * 过滤当前实体服务，标准接口数据
	 *
	 * @return {*}  {*}
	 * @memberof Auth_userServiceBase
	 */
	protected filterEntityData(entity: Auth_user): any {
		const data: any = {};
		Auth_userKeys.forEach((key) => {
			if (entity[key] !== void 0) {
				data[key] = entity[key];
			}
		});
		return data;
	}

	/**
	 * LoadUserByUsername
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof Auth_userServiceBase
	 */
	public async LoadUserByUsername(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auth_users/${encodeURIComponent(
			context['auth_user']
		)}/loaduserbyusername`;
		const res = await this.http.get(requestPath, data);
		res.data = await Auth_userDTOHelp.set(context, res.data);
		return res;
	}
}
